var _contextPath;

$(document).ready(function() {
	list();
	selectOpList();
	top.UppTabs.operator = top.getCurrentTagTitle();// 设置用户tab的标题值
});

/**
 * 查询用户列表
 */
function list() {
	_contextPath = $("#contextPath").val();
	$("#rcr_list").datagrid(
			{
				queryParams : {
					userId : $("#userId").val()
				},
				columns : [ [ {
					field : 'user_name',
					title : '销售人员',
					width : 100,
					align : 'center'
				}, {
					field : 'rechargeable_card_credit_amount',
					title : '未对账金额（元）',
					width : 100,
					align : 'center'
				}, {
					field : 'recently_account_date',
					title : '上次对账日期',
					width : 100,
					align : 'center',
					formatter : function(value, row, index) {
						if(typeof(value) == "undefined"){
							return "";
						}else{
							return (new Date(Number(value))).dateConvert();
						}
						//return value;
						//
					}
						
				},  {
					field : 'action',
					title : '操作',
					width : 120,
					align : 'center',
					formatter : function(value, row) {
						var vdate = (new Date(Number(row.recently_account_date))).dateConvert();
						return '<a href="'+getContextPath() +'iccard/rcreconciliation/dzlist.jsp?userId='+row.user_id+'&recentlyDate='+vdate+'">对账</a>';
					}
				}] ],
				autoRowHeight : true,
				fitColumns : true,
				pagination : true,
				rownumbers : true,
				singleSelect : true
			});
}
	window.top["reload_combocard_list"]=function(){
		$('#rcr_list').datagrid( "load");
	};
	function getContextPath() {
		if ("" == _contextPath) {
			_contextPath = $("#contextPath").val();
		}
		return _contextPath;
	}
	/**
	 * 搜索
	 * 
	 * @return
	 */
	function searchKey() {
		$('#rcr_list').datagrid('load', {
			userId : $("#userId").val()
		});
	}
	
	function selectOpList() {
		var roleId = 1001;
		$("#userId").empty();
		$.ajax({
			type : 'POST',
			url : contextPath + 'iccard/rechargecard/oplist',
			data : {
				'roleId' : roleId
			},
			dataType : 'json',
			success : function(list) {
				if (list != null && list.length>0) {
					$("#userId").append('<option value="">全部</option>');
					for ( var i = 0; i < list.length; i++) {
						var option = '<option value="' + list[i].operatorId + '">'
								+ list[i].userName + '</option>';
						$("#userId").append(option);
					}
				}
			}
		});
	}

